package com.xatu.yl.storeshopping.activity;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.namespace.R;
import com.xatu.yl.storeshopping.activity.Fragment.ShoppingInfoFragment.CommentFragment;
import com.xatu.yl.storeshopping.activity.Fragment.ShoppingInfoFragment.OrderShoppingFragment;
import com.xatu.yl.storeshopping.activity.Fragment.UserHomeFragment;
import com.xatu.yl.storeshopping.util.ChangeStateUtil;


public class ShoppingInfoActivity extends AppCompatActivity implements View.OnClickListener {

	private ImageView back,shopIcon;
	private TextView shopName,shopId;
	private TextView orderFood,comment;
	private LinearLayout orderFoodFocus,commentFocus;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_shopping_info);
		// 隐藏 ActionBar
		getSupportActionBar().hide();

		//返回
		back = findViewById(R.id.back);
		shopIcon = findViewById(R.id.shopIcon);
		orderFood = findViewById(R.id.orderFood);
		comment = findViewById(R.id.comment);
		orderFoodFocus = findViewById(R.id.orderFoodFocus);
		commentFocus = findViewById(R.id.commentFocus);

		shopId = findViewById(R.id.shopId);
		shopName = findViewById(R.id.shopName);

		shopIcon.setOnClickListener(this);
		orderFood.setOnClickListener(this);
		comment.setOnClickListener(this);
		back.setOnClickListener(this);

		//第一次进入这个页面,点餐显示被选中
		orderFoodFocus.setBackgroundColor(getResources().getColor(R.color.selected));
		commentFocus.setBackgroundColor(getResources().getColor(R.color.unselect));
		//设置未选中的文字颜色
		comment.setTextColor(getResources().getColor(R.color.unselectText));

		//打开商品页面，首先展示的就是点餐
		replaceFragment(new OrderShoppingFragment());
	}

	/**
	 * 点击切换fragment，动态
	 * @param endFragment
	 */
	private void replaceFragment(Fragment endFragment) {
		FragmentManager fragmentManager = getSupportFragmentManager();
		FragmentTransaction transaction = fragmentManager.beginTransaction();
		//其实多个fragment之间的切换：本质上就是从一个根fragment切换到目标fragment的过程
		transaction.replace(R.id.orderFood_Comment, endFragment);
		//提交事件
		transaction.commit();
	}

	@Override
	public void onClick(View v) {
		if(v.getId()==R.id.back){
			this.finish();
		}
		if(v.getId()==R.id.shopIcon){
			//点击商铺图标，跳转到商铺界面
			startActivity(new Intent(ShoppingInfoActivity.this,ShoppingInfoInShopActivity.class));
		}

		if(v.getId()==R.id.orderFood){
			orderFoodFocus.setBackgroundColor(getResources().getColor(R.color.selected));
			commentFocus.setBackgroundColor(getResources().getColor(R.color.unselect));

			orderFood.setTextColor(getResources().getColor(R.color.selectText));
			comment.setTextColor(getResources().getColor(R.color.unselectText));
			//打开商品页面，首先展示的就是点餐
			replaceFragment(new OrderShoppingFragment());
		}
		if(v.getId()==R.id.comment){
			//点击评论
			commentFocus.setBackgroundColor(getResources().getColor(R.color.selected));
			orderFoodFocus.setBackgroundColor(getResources().getColor(R.color.unselect));
			//设置文字颜色
			comment.setTextColor(getResources().getColor(R.color.selectText));
			orderFood.setTextColor(getResources().getColor(R.color.unselectText));

			//打开商品页面，首先展示的就是点餐
			replaceFragment(new CommentFragment());
		}
	}
}
